package com.shd.edanpei.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.bean.LendingBean;
import com.shd.edanpei.presenter.contract.SureOrderContract;
import com.shd.edanpei.presenter.SureOrderPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mc on 2018/7/10.
 * 确认放款
 */

public class SureOrderActivity extends BaseActivity<SureOrderPresenter> implements SureOrderContract.SureOrderIView {

    @BindView(R.id.root)
    View root;
    @BindView(R.id.headline)
    TextView tvHeadLine;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_amount)
    TextView tvAmount;
    @BindView(R.id.tv_bankname)
    TextView tvBankName;
    @BindView(R.id.tv_bankcard)
    TextView tvBankCard;
    @BindView(R.id.tv_bankbranch)
    TextView tvBankBranch;
    @BindView(R.id.tv_phone)
    TextView tvPhone;

    private Bundle extras;
    private int orderId, index, orderType;
    private LendingBean bean;

    @Override
    protected int setLayout() {
        return R.layout.activity_sureorder;
    }

    @Override
    protected SureOrderPresenter bindPresenter() {
        return new SureOrderPresenter(this);
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        tvHeadLine.setText("立即确认");
        extras = getIntent().getExtras();

        orderId = extras.getInt(Constant.ORDER_ID);
        index = extras.getInt(Constant.INDEX);
        orderType = extras.getInt(Constant.ORDER_TYPE);
        mPresenter.getLendingInfo(orderId);

    }

    @Override
    protected void initListener() {

    }

    @OnClick(R.id.iv_headline_back)
    void close() {
        finish();
    }

    @OnClick(R.id.tv_sure)
    void sure() {
        mPresenter.sureOrder(orderId, index, orderType);
    }

    @Override
    public void setLendingInfo(LendingBean bean) {
        this.bean = bean;
        root.setVisibility(View.VISIBLE);
        tvName.setText(bean.getName());
        tvAmount.setText(bean.getLastAmount() + Constant.Unit.WANYUAN.getUnit());
        tvBankName.setText(bean.getBankName());
        tvBankCard.setText(bean.getBankCard());
        tvBankBranch.setText(bean.getOpenAccountBank());
        tvPhone.setText(bean.getPhone());
    }
}
